package com.example.bms.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.FillQuestion;
import com.example.bms.mapper.FillQuestionMapper;
import com.example.bms.service.FillQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * @apiNote 实现对填空题的增加和查询
 * @author 钟顺浩
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
@Service
@Transactional
public class FillQuestionServiceImpl implements FillQuestionService {

    @Autowired
    private FillQuestionMapper fillQuestionMapper;


    /**
     * @apiNote 查询中等难度系数的填空题
     * @author 钟顺浩
     * @param paperId 试卷id
     * @email 2918185121@qq.com
     * @return List<FillQuestion>
     * @since 1.0.0
     */
    @Override
    public List<FillQuestion> findByIdAndType(Integer paperId) {
        return fillQuestionMapper.findByIdAndType(paperId);
    }


    /**
     * @apiNote 查询所有填空题
     * @author 钟顺浩
     * @param page 分页
     * @email 2918185121@qq.com
     * @return 以FillQuestion为数据类型的IPage对象集合
     * @since 1.0.0
     */
    @Override
    public IPage<FillQuestion> findAll(Page<FillQuestion> page) {
        return fillQuestionMapper.findAll(page);
    }


    /**
     * @apiNote 查询最后一条questionId
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return FillQuestion
     * @since 1.0.0
     */
    public FillQuestion findOnlyQuestionId() {
        return fillQuestionMapper.findOnlyQuestionId();
    }


    /**
     * @apiNote 增加一道填空题
     * @author 钟顺浩
     * @param fillQuestion 填空题对象
     * @email 2918185121@qq.com
     * @return int，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Override
    public int add(FillQuestion fillQuestion) {
        return fillQuestionMapper.add(fillQuestion);
    }


    /**
     * @apiNote 查询最后一条questionId
     * @author 钟顺浩
     * @param subject 科目
     * @param pageNo 页码
     * @email 2918185121@qq.com
     * @return List<Integer>
     * @since 1.0.0
     */
    @Override
    public List<Integer> findBySubject(String subject, Integer pageNo) {
        return fillQuestionMapper.findBySubject(subject,pageNo);
    }
}
